package com.acme.domain.account;

import com.acme.exceptions.NoEnoughFundsException;

public class SavingAccount extends AbstractAccount {

	public SavingAccount(final int id, final double amount) {
		super(id, amount);
	}

	@Override
	public void deposit(final double amount) throws IllegalArgumentException {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount can not be negative");
		}
		this.balance += amount;
	}

	@Override
	public void withdraw(final double amount) throws NoEnoughFundsException {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount can not be negative");
		}
		if (this.balance - amount >= 0) {
			this.balance -= amount;
		} else {
			throw new NoEnoughFundsException(amount);
		}

	}

	public AccountType getAccountType() {
		return AccountType.SAVING;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("Saving Account #" + this.id + " ");
		sb.append("balance: " + this.getBalance());
		return sb.toString();
	}
	
	@Override

	// TODO: [VY] Check the sinature of method at java.lang.Object and fix it
	public boolean Equals(Object obj) {
		if(obj instanceof SavingAccount) {
			SavingAccount sAcc = (SavingAccount)obj;
			return (sAcc.id == this.id && sAcc.balance == this.balance);
		}
		return false;
	}
	
	public int hashCode() {
s		// TODO: [VY] Ok, but in this case .hashCode() not needed. Try to think why ;)
		return ((Integer)this.id).hashCode();
	}
}
